package com.blt.car.me;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.TypedValue;
import android.view.View;

import com.blt.car.R;
import com.blt.car.base.BaseActivity;
import com.blt.car.base.ViewHolder;
import com.blt.car.widget.PagerSlidingTabStrip;

import java.util.ArrayList;


/**
 * Created by xgp on 2017/6/20.
 */

public class FeedBackActivity extends BaseActivity {
    // 指示器
    private PagerSlidingTabStrip tabs;
    private ViewPager viewPager;

    private ArrayList<Fragment> fragmentsList;
    private Fragment fbCommitFragment, fbTrackFragment;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_feedback;
    }

    @Override
    protected void initData() {
        super.initData();
    }

    @Override
    protected void initView(ViewHolder holder) {

        tabs = holder.get(R.id.feedback_tabs);
        viewPager = holder.get(R.id.vp_feedback);

        fragmentsList = new ArrayList<>();

        fbCommitFragment = new CommitFBFragment();
        fragmentsList.add(fbCommitFragment);

        fbTrackFragment = new FBTrackFragment();
        fragmentsList.add(fbTrackFragment);

        viewPager.setAdapter(new FBFragmentAdapter(getSupportFragmentManager(),
                fragmentsList));

        final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources()
                .getDisplayMetrics());
        viewPager.setPageMargin(pageMargin);

        tabs.setViewPager(viewPager);

        holder.get(R.id.title_bar_back_btn);
        holder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        }, R.id.title_bar_back_btn);
    }

    class FBFragmentAdapter extends FragmentPagerAdapter {

        //过路费明细 充值明细 退款明细
        private final String[] TITLES = {"提交反馈", "反馈追踪"};

        private ArrayList<Fragment> list;

        public FBFragmentAdapter(FragmentManager fm, ArrayList<Fragment> list) {
            super(fm);
            this.list = list;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return TITLES[position];
        }

        @Override
        public Fragment getItem(int arg0) {
            return list.get(arg0);
        }

        @Override
        public int getCount() {
            return list.size();
        }
    }
}